package io.jee.caisan.weixin.service.impl;

import javax.annotation.Resource;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import io.jee.alaska.util.Result;
import io.jee.caisan.weixin.domain.SysMember;
import io.jee.caisan.weixin.repository.SysMemberRepository;
import io.jee.caisan.weixin.service.SysMemberService;

@Service
@Transactional
public class SysMemberServiceImpl implements SysMemberService{

	@Resource
	private SysMemberRepository sysMemberRepository;
	
	@Resource
	private PasswordEncoder passwordEncoder;
	
	@Override
	public SysMember getSysMemberByUsername(String username) {
		return sysMemberRepository.select().where("username", username).end().unique();
	}

	@Override
	public Result<SysMember> addSysMember(SysMember sysMember) {
		sysMember.setPassword(passwordEncoder.encode(sysMember.getPassword()));
		sysMember = sysMemberRepository.save(sysMember);
		return Result.success(sysMember);
	}

}
